package com.example.demo.controller;


import com.example.demo.pojo.Teacher;
import com.example.demo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TeacherController {
    @Autowired
    private TeacherService teacherService;


    @RequestMapping(value = "/queryTeacher",method = RequestMethod.POST)
    public List<Teacher> queryTeacher(){
        return teacherService.queryTeacher();
    }


    @RequestMapping(value = "addTeacher",method = RequestMethod.POST)
    public String addTeacher(String teacher_name,int teacher_number,String teacher_sex,int teacher_age){
        if (teacher_name==""||teacher_number<2000||teacher_sex==""||teacher_age<=0){
            return "输入有误,添加失败";
        }
        else {
            teacherService.addTeacher(teacher_name,teacher_number,teacher_sex,teacher_age);
            return "增加教师成功";
        }

    }

    @RequestMapping(value = "updateTeacher",method = RequestMethod.POST)
    public String updateTeacher(Teacher teacher)
    {
        if (teacher!=null){
            teacherService.updateTeacher(teacher);
            return "修改教师信息成功";
        }
        else {
            return "修改教师信息失败";
        }
    }
    @RequestMapping(value = "deleteTeacher",method = RequestMethod.POST)
    public String deleteTeacher(Integer id){
        if (id!=null)
        {
            teacherService.deleteTeacher(id);
            return "删除成功";
        }
        else {
            return "删除失败";
        }
    }
}
